//
//  RelationViewController.m
//  XDD
//
//  Created by mao on 12/8/14.
//  Copyright (c) 2014 yuhaya. All rights reserved.
//

#import "RelationViewController.h"
#import "Tool.h"
#import "User.h"
#import "StudentListTableViewController.h"

@interface RelationViewController ()

@end

@implementation RelationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    [customLab setTextColor:[UIColor whiteColor]];
    [customLab setText:@"设置亲属关系"];
    customLab.textAlignment = NSTextAlignmentCenter;
    customLab.font = [UIFont boldSystemFontOfSize:16];
    self.navigationItem.titleView = customLab;
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStyleBordered target:self action:@selector(relationOver)];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
    self.relation.leftView = view;
    self.relation.leftViewMode = UITextFieldViewModeAlways;
    
    if(![self.relation_val isEqualToString:@""]){
        self.relation.text = self.relation_val;
    }
    // Do any additional setup after loading the view from its nib.
}
-(void) relationOver
{
    NSString * relation = self.relation.text;
    NSString * token = [User token];
    if(![relation  isEqual: @""]){
        NSString * url_stus_get = [NSString stringWithFormat:@"%@?token=%@",URL_RELATION_UPDATE,token];
        NSDictionary * par = [[NSDictionary alloc] initWithObjectsAndKeys:self.gen_id,@"uid",self.stu_id,@"student_id",relation,@"relation",nil];
        AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager manager];
        DLog(@"%@",par);
        [manager POST:url_stus_get parameters:par success:^(AFHTTPRequestOperation *operation, id responseObject) {
            
            NSDictionary * redata = responseObject;
            DLog(@"%@",redata);
//            NSArray * data = redata[@"data"];
            NSString * code = redata[@"code"];
            
            if(code.intValue  == 0){
                [Tool showMessage:@"设置成功!"];
                [self.navigationController popToRootViewControllerAnimated:YES];
            }else{
                [Tool showMessage:redata[@"msg"]];
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            [Tool showMessage:[error localizedDescription]];
        }];
        
    }else{
        [Tool showMessage:@"请设置亲属关系!"];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
